package com.irdstudio.efp.limit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.limit.service.dao.LmtShowSubInfoDao;
import com.irdstudio.efp.limit.service.domain.LmtShowSubInfo;
import com.irdstudio.efp.limit.service.facade.LmtShowSubInfoService;
import com.irdstudio.efp.limit.service.vo.LmtShowSubInfoVO;

/**
 * <p>
 * 手机银行首页展示信息子表的Service实现类
 * </p>
 * 
 * @author szbd
 * @createDate 2018-09-25 18:45:45
 */
@Service("lmtShowSubInfoService")
public class LmtShowSubInfoServiceImpl implements LmtShowSubInfoService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(LmtShowSubInfoServiceImpl.class);

	@Autowired
	private LmtShowSubInfoDao lmtShowSubInfoDao;

	@Override
	public List<LmtShowSubInfoVO> queryAllOwner(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("查询本人所属的手机银行首页展示信息子表记录的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			List<LmtShowSubInfo> dataList = lmtShowSubInfoDao.queryAllOwnerByPage(inLmtShowSubInfoVo);
			if (Objects.nonNull(dataList)) {
				List<LmtShowSubInfoVO> resultList = new ArrayList<LmtShowSubInfoVO>();
				resultList = (List<LmtShowSubInfoVO>) beansCopy(dataList, LmtShowSubInfoVO.class);
				return resultList;
			} else {
				logger.info("查询本人所属的手机银行首页展示信息子表记录为空！");
			}
		} catch (Exception e) {
			logger.error("查询本人所属的手机银行首页展示信息子表记录发生异常！", e);
		}
		return null;
	}

	@Override
	public List<LmtShowSubInfoVO> queryAllCurrOrg(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("查询本机构的手机银行首页展示信息子表记录的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			List<LmtShowSubInfo> dataList = lmtShowSubInfoDao.queryAllCurrOrgByPage(inLmtShowSubInfoVo);
			if (Objects.nonNull(dataList)) {
				List<LmtShowSubInfoVO> resultList = new ArrayList<LmtShowSubInfoVO>();
				resultList = (List<LmtShowSubInfoVO>) beansCopy(dataList, LmtShowSubInfoVO.class);
				return resultList;
			} else {
				logger.info("查询本机构的手机银行首页展示信息子表记录为空！");
			}
		} catch (Exception e) {
			logger.error("查询本机构的手机银行首页展示信息子表记录发生异常！", e);
		}
		return null;
	}

	@Override
	public List<LmtShowSubInfoVO> queryAllCurrDownOrg(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("查询本机构及下属机构的手机银行首页展示信息子表记录的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			List<LmtShowSubInfo> dataList = lmtShowSubInfoDao.queryAllCurrDownOrgByPage(inLmtShowSubInfoVo);
			if (Objects.nonNull(dataList)) {
				List<LmtShowSubInfoVO> resultList = new ArrayList<LmtShowSubInfoVO>();
				resultList = (List<LmtShowSubInfoVO>) beansCopy(dataList, LmtShowSubInfoVO.class);
				return resultList;
			} else {
				logger.info("查询本机构及下属机构的手机银行首页展示信息子表记录为空！");
			}
		} catch (Exception e) {
			logger.error("查询本机构及下属机构的手机银行首页展示信息子表记录发生异常！", e);
		}
		return null;
	}

	@Override
	public int insertLmtShowSubInfo(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("新增手机银行首页展示信息子表数据的参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return 0;
		}
		int count = 0;
		try {
			LmtShowSubInfo lmtShowSubInfo = new LmtShowSubInfo();
			beanCopy(inLmtShowSubInfoVo, lmtShowSubInfo);
			count = lmtShowSubInfoDao.insertLmtShowSubInfo(lmtShowSubInfo);
		} catch (Exception e) {
			logger.error("新增手机银行首页展示信息子表数据发生异常！", e);
			count = -1;
		}
		logger.info("当前新增手机银行首页展示信息子表数据条数为：" + count);
		return count;
	}

	@Override
	public int deleteLmtShowSubInfoByPk(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("删除手机银行首页展示信息子表数据的参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return 0;
		}
		int count = 0;
		try {
			LmtShowSubInfo lmtShowSubInfo = new LmtShowSubInfo();
			beanCopy(inLmtShowSubInfoVo, lmtShowSubInfo);
			count = lmtShowSubInfoDao.deleteLmtShowSubInfoByPk(lmtShowSubInfo);
		} catch (Exception e) {
			logger.error("删除手机银行首页展示信息子表数据发生异常！", e);
			count = -1;
		}
		logger.info("删除的手机银行首页展示信息子表数据条数为：" + count);
		return count;
	}

	@Override
	public int updateLmtShowSubInfoByPk(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("修改手机银行首页展示信息子表数据的参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return 0;
		}
		int count = 0;
		try {
			LmtShowSubInfo lmtShowSubInfo = new LmtShowSubInfo();
			beanCopy(inLmtShowSubInfoVo, lmtShowSubInfo);
			count = lmtShowSubInfoDao.updateLmtShowSubInfoByPk(lmtShowSubInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常！", e);
			count = -1;
		}
		logger.info("修改的手机银行首页展示信息子表数据条数为" + count);
		return count;
	}

	@Override
	public LmtShowSubInfoVO queryLmtShowSubInfoByPk(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("根据主键查询手机银行首页展示信息子表的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			LmtShowSubInfo lmtShowSubInfo = new LmtShowSubInfo();
			beanCopy(inLmtShowSubInfoVo, lmtShowSubInfo);
			lmtShowSubInfo = lmtShowSubInfoDao.queryLmtShowSubInfoByPk(lmtShowSubInfo);
			if (Objects.nonNull(lmtShowSubInfo)) {
				LmtShowSubInfoVO outLmtShowSubInfoVo = beanCopy(lmtShowSubInfo, new LmtShowSubInfoVO());
				return outLmtShowSubInfoVo;
			} else {
				logger.info("根据主键查询手机银行首页展示信息子表的记录为空！");
			}
		} catch (Exception e) {
			logger.error("根据主键查询手机银行首页展示信息子表记录发生异常！", e);
		}
		return null;
	}

	@Override
	public LmtShowSubInfoVO querySingleLmtShowSubInfoByCondition(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("根据条件查询单笔手机银行首页展示信息子表的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			LmtShowSubInfo lmtShowSubInfo = new LmtShowSubInfo();
			beanCopy(inLmtShowSubInfoVo, lmtShowSubInfo);
			lmtShowSubInfo = lmtShowSubInfoDao.querySingleLmtShowSubInfoByCondition(lmtShowSubInfo);
			if (Objects.nonNull(lmtShowSubInfo)) {
				LmtShowSubInfoVO outLmtShowSubInfoVo = beanCopy(lmtShowSubInfo, new LmtShowSubInfoVO());
				return outLmtShowSubInfoVo;
			} else {
				logger.info("根据条件查询单笔手机银行首页展示信息子表的记录为空！");
			}
		} catch (Exception e) {
			logger.error("根据条件查询单笔手机银行首页展示信息子表记录发生异常！", e);
		}
		return null;
	}

	@Override
	public List<LmtShowSubInfoVO> queryLmtShowSubInfoByCondition(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("条件查询手机银行首页展示信息子表的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			List<LmtShowSubInfo> dataList = lmtShowSubInfoDao.queryLmtShowSubInfoByCondition(inLmtShowSubInfoVo);
			if (Objects.nonNull(dataList)) {
				List<LmtShowSubInfoVO> resultList = new ArrayList<LmtShowSubInfoVO>();
				resultList = (List<LmtShowSubInfoVO>) beansCopy(dataList, LmtShowSubInfoVO.class);
				return resultList;
			} else {
				logger.info("条件查询手机银行首页展示信息子表的数据为空！");
			}
		} catch (Exception e) {
			logger.error("条件查询手机银行首页展示信息子表发生异常！", e);
		}
		return null;
	}

	@Override
	public List<LmtShowSubInfoVO> queryLmtShowSubInfoByConditionByPage(LmtShowSubInfoVO inLmtShowSubInfoVo) {
		logger.info("条件分页查询手机银行首页展示信息子表的请求参数为：" + JSONObject.toJSONString(inLmtShowSubInfoVo));
		if (Objects.isNull(inLmtShowSubInfoVo)) {
			return null;
		}
		try {
			List<LmtShowSubInfo> dataList = lmtShowSubInfoDao.queryLmtShowSubInfoByConditionByPage(inLmtShowSubInfoVo);
			if (Objects.nonNull(dataList)) {
				List<LmtShowSubInfoVO> resultList = new ArrayList<LmtShowSubInfoVO>();
				resultList = (List<LmtShowSubInfoVO>) beansCopy(dataList, LmtShowSubInfoVO.class);
				return resultList;
			} else {
				logger.info("条件分页查询手机银行首页展示信息子表的数据为空！");
			}
		} catch (Exception e) {
			logger.error("条件分页查询手机银行首页展示信息子表发生异常！", e);
		}
		return null;
	}
}